var CandidateJobPreference = {
	getJobPreferenceGrid: function() {
		ajax({
			  url: baseURL + "candidate/job_preference",
			  cache: false,
			  type: "POST",
			  data: $('#ajax_form').serialize(),
			  async: false,
			  dataType: 'html',
			  success: function(data) {
				  $('#gridJobPreference').html(data);
			  }
			});
	},
	
	getJobHierarchy: function() {
		ajax({
			  url: baseURL + "ajax/get_job_hierarchy/multiple/any",
			  cache: false,
			  type: "POST",
			  async: false,
			  dataType: 'html',
			  success: function(data) {
				  $('#jobHierarchy').html(data);
			  }
			});
	},
	
	getJobCategory: function() {
		ajax({
			  url: baseURL + "ajax/get_job_category/CandidateJobPreference",
			  cache: false,
			  type: "POST",
			  async: false,
			  dataType: 'html',
			  success: function(data) {
				  $('#jobCategory').html(data);
			  }
			});
	},
	
	getJobSpecialty: function() {
		if ($('#idcategory').val()) {
			ajax({
				  url: baseURL + "ajax/get_job_specialty/multiple/any",
				  cache: false,
				  type: "POST",
				  async: false,
				  data: 'idcategory=' + $('#idcategory').val(),
				  dataType: 'html',
				  success: function(data) {
					  $('#jobSpecialty').html(data);
				  }
				});
		} else {
			$('#jobSpecialty').html('<div>' + ajax_lang[2] + '</div>');
		}
	},

	editJobPreference: function(idjob_preference) {
		$.facebox(function() {
			ajax({
			  url: baseURL + "candidate/job_preference/edit/" + idjob_preference,
			  cache: false,
			  type: "POST",
			  async: false,
			  dataType: 'html',
			  success: function(data) { $.facebox(data) }
			});
		});
		
		return false;
	},
	
	processJobPreference: function() {
		
		var idSpecialty = [];
		var idHierarchy = [];
		var idState = [];
		
		$('#idspecialty :selected').each(function(i, selected) {
			idSpecialty[i] = $(selected).val();
		});
		
		$('#idhierarchy :selected').each(function(i, selected) {
			idHierarchy[i] = $(selected).val();
		});
		
		$('#idstate :selected').each(function(i, selected) {
			idState[i] = $(selected).val();
		});
		
		ajax({
		  url: baseURL + "candidate/job_preference/" + ($('#idjobpreference').val() ? 'update' : 'insert'),
		  cache: false,
		  type: "POST",
		  data: $('#ajax_form').serialize() + '&specialty=' + idSpecialty.join(',')
		  		+ '&hierarchy=' + idHierarchy.join(',')
		  		 + '&state=' + idState.join(','),
		  async: false,
		  dataType: 'script'
		});
		
		return false;
	},
	
	deleteJobPreference: function(idjob_preference) {
		ajax({
			  url: baseURL + "candidate/job_preference/delete",
			  cache: false,
			  type: "POST",
			  data: 'id=' + idjob_preference,
			  async: false,
			  dataType: 'script'
			});
			
			return false;
	}
};